/**
 * 
 */
package com.gopay.common.user.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.user.dao.DicProvinceCityDao;

/**
 * @DicProvinceCityDaoImpl.java
 * @author gaocl
 * @2016年11月8日 上午9:47:40  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("dicProvinceCityDao")
public class DicProvinceCityDaoImpl extends BaseDAOImpl<Object[],String>implements DicProvinceCityDao {

    
    @Override
    public List<Object[]> getProvinceList() {
        String hql = "SELECT PI.proCode,PI.proName FROM  GopayMccProvince PI WHERE 1=1";
        return findByHql(hql);
    }
    
    @Override
    public List<Object[]> getRegionList(String provinceCode) {
        
        String sq = "SELECT PI.proName,PI.refCode FROM  GopayMccProvince PI WHERE PI.proCode =:provinceCode";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("provinceCode", provinceCode);
        List<Object[]> list = findByHql(sq, paramMap);
        for (Object[] obj : list) {
            if(obj[1] != null){
                provinceCode= (String)obj[1];  
            }
        }
        String hql = "SELECT ci.code,ci.name FROM DicRegionInfo ci WHERE ci.delFlag=0 and ci.provinceCode =:provinceCode ";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("provinceCode", provinceCode);
        return findByHql(hql, param);
    }
    @Override
    public String getProvinceName(String provinceCode){
        String sq = "SELECT PI.proName,PI.refCode FROM  GopayMccProvince PI WHERE PI.proCode =:provinceCode";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("provinceCode", provinceCode);
        List<Object[]> list = findByHql(sq, paramMap);
        for (Object[] objects : list) {
            if(objects[0]!=null){
              return (String)objects[0];
            }
        }
        return null;
    }
    @Override
    public String getCityName(String cityCode){
        String hql = "SELECT ci.code,ci.name FROM DicRegionInfo ci WHERE ci.delFlag=0 and ci.code =:cityCode ";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("cityCode", cityCode);
        List<Object[]> list = findByHql(hql, param);
        for (Object[] objects : list) {
            if(objects[1]!=null){
              return (String)objects[1];
            }
        }
    return null;
    }

    @Override
    public List<Object[]> getCountryList(String gopayMccCode) {

        String sq = "SELECT PI.code, PI.name FROM DicCityCodeTranferScan PI WHERE PI.mccCode =:gopayMccCode";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("gopayMccCode", gopayMccCode);
        List<Object[]> list = findByHql(sq, paramMap);
        if(!list.isEmpty()) {
            gopayMccCode = (String) list.get(0)[0];
        }

        String hql = "SELECT ci.code,ci.name FROM DicCountryInfoScan ci WHERE ci.delFlag=0 and ci.cityCode =:gopayMccCode ";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("gopayMccCode", gopayMccCode);
        return findByHql(hql, param);

    }

    @Override
    public String getCountryName(String countryCode){
        String hql = "SELECT ci.code,ci.name FROM DicCountryInfoScan ci WHERE ci.delFlag=0 and ci.code =:countryCode ";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("countryCode", countryCode);
        List<Object[]> list = findByHql(hql, param);
        for (Object[] objects : list) {
            if(objects[1]!=null){
                return (String)objects[1];
            }
        }
        return null;
    }

    @Override
    public String getBankCityCode(String gopayMccCode) {
        String sq = "SELECT PI.code, PI.name FROM DicCityCodeTranferScan PI WHERE PI.mccCode =:gopayMccCode";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("gopayMccCode", gopayMccCode);
        List<Object[]> list = findByHql(sq, paramMap);
        for (Object[] obj : list) {
            if(obj[1] != null){
                return (String)obj[0];
            }
        }
        return "";
    }
}
